import java.util.Random;
import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        //生成1-100之间的随机整数
        Random random = new Random();
        Scanner scanner= new Scanner(System.in);
        while(true){
        int ran = random.nextInt(100);
        //循环判断答案
        int ci =7;
        while (ci>0){
        //从命令行提示并接收用户猜测数字
        System.out.println("请输入您猜测的数字");

        int userNum =scanner.nextInt();
        ci--;
        //比对答案
        if (userNum==ran){
            System.out.println("恭喜您，猜对了！！！");
            break;
        }else if(userNum>ran){
            System.out.println("抱歉，您猜大了");
            if (ci!=0)
            System.out.println("您还有"+ci+"次机会");
        }else{
            System.out.println("抱歉，您猜小了");
            if (ci!=0)
            System.out.println("您还有"+ci+"次机会");
        }
        }

            System.out.println("输入N结束游戏 输入Y再来一局");
            String play = scanner.next();
            if ("N".equals(play)||"n".equals(play)){
                break;
            }
        }
    }
}
